<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<div id="lineTab" class="tab-pane">
	<div class="panel-body" style="padding-bottom: 0px; border-bottom: 0px;">

		<div class="col-lg-12 text-right" style="padding-right: 0px;">
			<button id="addButton" class="btn btn-info btn-sm" type="button" ><i class="fa fa-plus"></i>&nbsp;&nbsp;<span class="bold redragon-line-button-title">新增入库行</span></button>
			<%--
			<button id="searchButton" class="btn btn-default btn-sm" type="button"><i class="fa fa-search"></i>&nbsp;&nbsp;展开查询</button>
			--%>
		</div><br/>

		<div class="table-responsive">
			<table class="table table-stripped table-hover table-bordered border-top">

				<thead>
				<tr>
					<th width="5%">行号</th>
					<th>物料编码</th>
					<th>物料名称</th>
					<th>规格型号</th>
					<th>单价</th>
					<th>单位</th>
					<th>金额</th>
					<th>采购数量</th>
					<th>供货数量</th>
					<th class="redragon-td-inputQuantity-title">入库数量</th>
					<th>损耗数量</th>
					<th>赠送数量</th>
					<th width="10%">操作</th>
				</tr>
				</thead>
				<tbody>

				<c:forEach items="${requestScope.invInputLineList}" var="data" varStatus="status">
					<tr>
						<td>${status.count}</td>
						<td>${data.a_material_code}</td>
						<td>${data.material_name}</td>
						<td>${data.standard}</td>
						<td>${data.price}</td>
						<td>${data.standard_unit}</td>
						<td>${data.allPrice}</td>
						<td>0</td>
						<td>${data.num}</td>
						<td>${data.num}</td>
						<td>${data.loss}</td>
						<td>${data.give}</td>
						<%--<td>${data.amount}</td>
						<td class="lineAmount" style="color: #1c84c6 !important;">${data.inputQuantity}</td>
						<td style="color: #1c84c6 !important;">${data.memo}</td>--%>

						<td>
							<div class="btn-group">
								<button class="btn-white edit-btn btn-xs" onclick="editData()"><i class="fa fa-edit"></i>&nbsp;入库</button>&nbsp;
								<%--<button class="btn-white del-btn btn-xs" onclick="deleteData(${data.inputLineId})"><i class="fa fa-trash"></i>&nbsp;删除</button>--%>
							</div>
						</td>
					</tr>
				</c:forEach>

				</tbody>
				<tfoot>
				<%-- 导入页码 --%>
				<jsp:include page="../../common/pages.jsp"></jsp:include>
				</tfoot>
			</table>

		</div>

	</div>
</div>

<div id="selectPOLineModal"></div>
<div id="addLineModal"></div>

<script>
    $(document).ready(function() {
        //入库类型切换效果
        if($("#inputType").val()=="RETURN"){
            $(".redragon-line-button-title").text("新增退货行");
            $(".redragon-td-inputQuantity-title").text("退货数量");
            $(".lineAmount").css("color", "red");

        }else{
            $(".redragon-line-button-title").text("新增入库行");
            $(".redragon-td-inputQuantity-title").text("入库数量");
            $(".lineAmount").css("color", "#1c84c6");
        }

/*
        if(true){
            alert();
            document.getElementById("aa").innerHTML = "0";
		}*/
        //添加行
        $("#addButton").click(function(){
            //订单入库则选择订单行
            getSelectDeliveryNoteModal();
        });

        /*
        $("#searchButton").click(function(){
            if($("#searchDiv").css("display")=="none"){
                $("#searchDiv").show();
                $("#searchButton").html('<i class="fa fa-search"></i>&nbsp;&nbsp;关闭查询');
                $("#searchButton").addClass("btn-outline btn-warning");
                $("#searchButton").blur();
            }else{
                $("#searchDiv").hide();
                $("#searchButton").html('<i class="fa fa-search"></i>&nbsp;&nbsp;展开查询');
                $("#searchButton").removeClass("btn-outline btn-warning");
                $("#searchButton").blur();
            }
        });
        */
    });

    function editData(){
        //getLineModal(id);
        //edit();
        alert("测试");
        window.location.href="web/invInputLine/invInputLineEdit";
    }

   /* function deleteData(id) {
        redragonJS.confirm("确认删除数据？", function(){
            deleteLine(id);
        });
    }*/


    function getLineModal(id, poLineCode, materialCode, materialName, price, quantity, unit, lineAmount, standard){
        $.ajax({
            type: "post",
            url: "web/invInputLine/getInvInputLine",
            data: {"inputLineId": id, "inputHeadCode": "${param.inputHeadCode}", "inputSourceType": $("#inputSourceType").val(),
                "inputSourceHeadCode": $("#inputSourceHeadCode").val(), "inputSourceLineCode": poLineCode, "materialCode": materialCode,
                "materialName": materialName, "price": price, "quantity": quantity, "unit": unit, "poLineAmount": lineAmount, "materialStandard": standard, "inputType": $("#inputType").val()},
            async: false,
            dataType: "html",
            cache: false,
            success: function(data){
                if(data!=""){
                    debugger
                    $("#addLineModal").html(data);
                    $('#addLineDiv').modal('show');
                    $(".modal-backdrop").remove();
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
                redragonJS.alert(textStatus);
            }
        });
    }

    function deleteLine(id){
        $.ajax({
            type: "post",
            url: "web/invInputLine/deleteInvInputLine",
            data: {"inputLineId": id, "inputHeadCode": "${param.inputHeadCode}"},
            async: false,
            dataType: "html",
            cache: false,
            success: function(data){
                var json = JSON.parse(data);
                if(json.result=="success"){
                    redragonJS.close();
                    getLineTab("${param.inputHeadCode}");
                }else{
                    redragonJS.alert("删除入库行错误");
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
                redragonJS.alert(textStatus);
            }
        });
    }

    //返回采购订单行选择框
    function getSelectDeliveryNoteModal(){
        $('#selectPOLineDiv').modal('hide');
        redragonJS.loading("ibox-content1");
        $.ajax({
            type: "post",
            url: "web/invInputLine/getSelectDeliveryNoteModal",
            data: {"deliveryCode": $("#inputSourceHeadCode").val()},
            async: false,
            dataType: "html",
            cache: false,
            success: function(data){
                redragonJS.removeLoading("ibox-content1");
                if(data!=""){
                    $("#selectPOLineModal").html(data);
                    $('#selectPOLineDiv').modal('show');
                    $(".modal-backdrop").remove();
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown){
                redragonJS.alert(textStatus);
            }
        });
    }
</script> 